package com.hisan.freeride.common.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 数据库类
 * @author admin
 *
 */
public class DBHelper extends SQLiteOpenHelper {
    //数据库名称
    private static final String DB_NAME="freerides.db";
    //城市重要参数表
    public static final String CITY_TOKEN="wxcity";
    //创建城市基站的sql语句
    private static final String CITY_TBL="create table " + CITY_TOKEN +"(_id INTEGER primary key autoincrement,"+ "id text,city text)";
    //SQLiteDatebase实例
    private SQLiteDatabase database;
    //数据库帮助类
    public static DBHelper helper;

    /**
     * 构造方法
     * @param context
     */
    public  DBHelper(Context context) {
        super(context, DB_NAME, null, 3);
    }

    public static DBHelper getInstace(Context context){
        if (helper==null) {
            helper=new DBHelper(context);
        }
        return helper;
    }
    /**
     * 创建表
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        this.database=db;
        database.execSQL(CITY_TBL);
    }

    //版本更新后调用，重新创建表
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
